package com.louis.pluginproject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.louis.stander.ReceiverInterface;

public class ProxyReceiver extends BroadcastReceiver {

    private String pluginMyReceiverClassName;

    public ProxyReceiver(String pluginMyReceiver) {
        this.pluginMyReceiverClassName = pluginMyReceiver;
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        //加载插件里面的MyReceiver
        try {
            Class<?> myReceiverClass = PluginManager.getInstance(context).getDexClassLoader().loadClass(pluginMyReceiverClassName);
            Object myReceiverObject = myReceiverClass.newInstance();
            ReceiverInterface receiverInterface = (ReceiverInterface) myReceiverObject;
            receiverInterface.onReceive(context,intent);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
